<!DOCTYPE html>
<html>

<head>
    <title>用户注册</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="stylesheet" href="{$Think.config._index_}css/author_register300.css">
    <script src="{$Think.config._index_}js/jquery-1.12.4.min.js"></script>
    <script src="{$Think.config._index_}js/tcaptcha.js"></script>
    <!--[if lt IE 9]>
    <script src=”http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js”></script>
    <![endif]-->
</head>

<body id="content">
<!-- header -->
<div class="header">
    <div class="boxCenter clearfix">
        <a href="/" class="tdLogo">辰星中文网&nbsp;&nbsp;&nbsp;</a>
        <!--<a href="http://author.tadu.com" class="atLogo">用户注册</a>-->

        <!-- 未登录 -->
        <div class="hdRight">
            <a href="/" class="taBack">返回首页<i></i></a>
        </div>

    </div>
</div>    <div class="register_box">
    <div class="to_login_box clearfix">
        <h4>注册辰星帐号</h4>
        <p>已有帐号，</p>
        <a href="/index/login/index">立即登录</a>
    </div>
    <div class="step_box">
        <div class="step_one current">
            填写注册信息
        </div>
        <!--<span class="next_log"> > </span>-->
        <!--<div class="step_two">-->
            <!--<span>2</span> 注册成功-->
        <!--</div>-->
    </div>
    <div class="reg-form-wrap">
        <div class="reg-form-list form-list">
            <dl>
                <dd class="top" id="phone">
                    <em>账号</em>
                    <input type="text" placeholder="输入账号" id="txtphonenumber">
                    <i class=""></i>&nbsp;&nbsp;<br>
                    <div id="phoneMsg" style="color:red;"></div>
                </dd>
                <dd class="top" id="nick">
                    <em>注册名</em>
                    <input type="text" placeholder="请输入昵称" id="nickName">
                    <i class=""></i>&nbsp;&nbsp;<br>
                    <div id="nickNameMsg" style="color:red;"></div>
                </dd>
                <dd>
                    <em>验证码</em>
                    <img src="{:captcha_src()}" alt="验证码，看不清楚，换一张" onclick="(this.src = this.src + '?' + Math.floor(Math.random()*100))" />
                    <input type="text" name="captcha" style="width:28%"><span id="captcha" style="color:red;"></span>
                    <!--<p ></p>-->
                </dd>


                <dd id="phonepwd" class="">
                    <em>密码</em>
                    <input type="password" id="txtphonepwd" minlength="6" maxlength="18" placeholder="仅支持：6-16位大小写字母或数字">
                    <i class=""></i>
                    <div class="password-tip" style="display: none;">
                        <span><cite></cite></span>
                        <p id="pwdrule1" class="">仅支持：6-16位大小写字母或数字</p>
                    </div>
                </dd>
                <dd id="phonepwd2">
                    <em>确认密码</em>
                    <input type="password" id="txtphonepwd2" placeholder="再次输入密码">
                    <i class=""></i><br>
                    <div style="color:red;" id="passMsg"></div>
                </dd>
            </dl>
            <div>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="checkbox" name="green">
                <label>我已阅读并同意</label><a href="/index/register/agreement" target="_blank">《用户服务协议》</a>
                <span style="color:red;" id="greenmsg"></span>
            </div>
            <a class="go-reg" href="javascript:;" id="btnPhoneRegister">下一步</a>
        </div>
    </div>
</div>
<!-- foot -->

</body>
<!--<script src="{$Think.config._index_}js/author_register300.js"></script>-->
<script>
    //检测是否勾选
    $("input[type='checkbox']").click(function(){
        var green = $("input[type='checkbox']").is(':checked');
        if(green){
            $("#greenmsg").html("");
        }
    });
    //检验手机号
    $("#txtphonenumber").blur(function(){
        var texphonenumber = $("#txtphonenumber").val();
        if(texphonenumber.length == 0){
            $("#phoneMsg").html("账号不能为空");
            return false;
        }else{
            $("#phoneMsg").html("");
        }
        // if(phoneFun(texphonenumber)){
        //     $("#phoneMsg").html("");
        // }else{
        //     $("#phoneMsg").html("手机号格式不正确");
        //         return false;
        // }
    });
    //检测验证码
    $("input[name='captcha']").blur(function(){
        var capcha =  $("input[name='captcha']").val();
        // alert(capcha.length);
        if(capcha.length > 0){
            // alert("111");
            $("#captcha").html("");
        }else{
            $("#captcha").html("验证码不能为空");
            return false;
        }
    });
    $("#btnPhoneRegister").click(function(){
        var green = $("input[type='checkbox']").is(':checked');
        if(!green){
            $("#greenmsg").html("提示:请先勾选用户服务协议");
            return false;
        };
        // alert(green);
        var texphonenumber = $("#txtphonenumber").val();
        var txtphonepwd = $("#txtphonepwd").val();
        var txtphonepwd2 = $("#txtphonepwd2").val();
        var nickName = $("#nickName").val();
        var captcha = $("input[name='captcha']").val();
        // alert(nickName);
        //检测两个密码是否一致
        if(txtphonepwd != txtphonepwd2){
            $("#passMsg").html("您2次输入的密码不一致");
            // alert(111);
            return false;
        }
        $.post("/index/register/register",{val1:texphonenumber,val2:txtphonepwd,val3:txtphonepwd2,val4:captcha,val5:nickName},function(data){
            // alert(data);
            // console.log(data.state);
            if(data.state === 200){
                window.location.href="/index/login/index";
            }else{
                if(data.state === -1){
                    $("#passMsg").html("您2次输入的密码不一致");
                }
                if(data.state === -2){
                    $("#captcha").html("验证码不正确");
                }
                if(data.state === -3){
                    alert("系统出错，请稍后再试");
                }
                if(data.state === -4){
                    $("#phoneMsg").html("该账号已注册");
                }
            }
        });
    });
    //判断是否为手机号的正则表达式
    function phoneFun(phones){
        var myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
        if (!myreg.test(phones)) {
            // console.log('手机号格式不正确')
            return false;
        } else {
            // console.log('手机号格式正确')
            return true;
        }
    }
</script>
</html>